//
//  XMBannerUserInfoView.m
//  XunMi
//
//  Created by MacBook on 2024/2/20.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMBannerUserInfoView.h"

@interface XMBannerUserInfoView ()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UILabel *nameLa;
@property (weak, nonatomic) IBOutlet UIView *onLineV;
@property (weak, nonatomic) IBOutlet UILabel *onLineLa;
@property (weak, nonatomic) IBOutlet UIButton *guardBtn;

@end

@implementation XMBannerUserInfoView

- (void)setModel:(XMUserModel *)model {
    _model = model;
    self.nameLa.text = model.showName;
    self.nameLa.textColor = model.showColor;

    if (model.is_online.intValue == 0) {
        self.onLineLa.text = @"刚刚活跃";
        self.onLineV.backgroundColor = kHEX(@"#E3E3E3");
    } else if (model.is_online.intValue == 1) {
        self.onLineLa.text = @"在线";
        self.onLineV.backgroundColor = kHEX(@"#1CCE37");
    } else {
        self.onLineLa.text = @"离线";
        self.onLineV.backgroundColor = kHEX(@"#E3E3E3");
    }
    
    self.guardBtn.selected = model.is_watch;
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (IBAction)guardAct:(UIButton *)sender {
    if (self.guardBlock) {
        self.guardBlock();
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    // 设置左上和右上的圆角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_bgView.bounds
                                                   byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
                                                         cornerRadii:CGSizeMake(20.0, 20.0)];

    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = _bgView.bounds;
    maskLayer.path = maskPath.CGPath;
    _bgView.layer.mask = maskLayer;

}

//- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
//    return nil;
//}

@end
